package violencerecursion;

import java.util.LinkedList;
import java.util.List;

/**
 * @author tongchen
 * @create 2023-03-15 16:37
 */
public class Subsequence {
    public static void main(String[] args) {
        String s="abcde";
        System.out.println(allSubsequence(s));
    }
    public static List<String> allSubsequence(String target){
        //将字符串转化为字符数组（便于遍历）
        char[]chars=target.toCharArray();
        //创建结果集
        LinkedList<String> end = new LinkedList<>();
        int index=0;//定义遍历位置
        process(chars,end,index,"");
        return end;
    }

    private static void process(char[] chars, LinkedList<String> end, int index,String path) {
        //确认终止条件
        if(index==chars.length){
            //将结果加入到结果集
            end.add(path);
            return ;
        }
        //对于当前结点有两种处理策略：1.当前结点不加入结果集2.当前结点加入结果集
        String no=path;
        process(chars, end, index+1, no);
        String yes=path+String.valueOf(chars[index]);
        process(chars, end, index+1, yes);
    }
}
